﻿/*专利监控图表*/

function PieChart(pieCharto) {
    this.pierender = pieCharto.dom;
    this.pietitle = pieCharto.pietitle ? pieCharto.pietitle : " ";
    this.piedata = pieCharto.piedata;
    this.subtitle = pieCharto.subtitle ? pieCharto.subtitle : "";
    this.bgColor = pieCharto.bgColor ? pieCharto.bgColor : "#fafcfe";
    var self = this;
    return new Highcharts.Chart({
        chart: {
            renderTo: self.pierender,
            backgroundColor: self.bgColor,
            plotBorderWidth: null,
            plotShadow: false,
            type: 'pie'
        },
        title: {
            text: self.pietitle,
            floating: true,
            y: 44,
            style: {
                color: "#5d6665"
            }
        },
        subtitle: {
            text: self.subtitle,
            y: 60,
            floating: true,
            style: {
                color: "#fe7200"
            }
        },
        tooltip: {
            style: {
                fontFamily: "微软雅黑",
                fontSize: '13px'
            },
            pointFormat: '{point.y}件({point.percentage}%)</b>',
            percentageDecimals: 1
        },
        plotOptions: {
            pie: {
                size: 140,
                cursor: 'pointer',
                dataLabels: {
                    distance: -1, //列上信息显示
                    enabled: false,
                    style: {
                        fontFamily: "微软雅黑",
                        fontSize: '13px'
                    },
                    color: '#333',
                    connectorColor: '#000000',
                    formatter: function() {
                        return this.point.name + '<br/>' +
                            this.point.y + ' 件';
                    }
                },
                showInLegend: true
            }
        },
        credits: {
            enabled: false
        },
        legend: {
            align: 'right',
            layout: 'vertical',
            verticalAlign: 'bottom',
            floating: true,
            backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white',
            borderWidth: 0
        },
        colors: ['#ebb867', '#6b9fcf','#8bc267'],
        // colors: ["#feb754", "#84c354", "#6ba2da"],
        series: [{
            type: 'pie',
            name: 'Browser share',
            data: self.piedata[0]
        }]
    });
}

function PieChange(valChartTab, isYear, 
	isArea, pieChart, totolA, title, subtitle,isShort) {
    isShort = isShort || false;

    return valChartTab.hover(function () {
        valChartTab.removeClass("hovertr");
        $(this).addClass("hovertr");
        var thisyear;
        if (isYear) {
            thisyear = $(this).find(".sta-year-tab-y").html();
        }
        var j = valChartTab.index($(this)), //获取当前tr索引
             flag = false, //饼图显示开关
             nodata = $(".nodata"); //无数据图片
        if (isArea) {
            if (j >= 0) {
                var areaTitle = $(".areaname").eq([j]).html();
                if (isShort && areaTitle) {
                    var splitArray = (areaTitle || []).split(':') || [];
                    if (splitArray.length > 0) {
                        areaTitle = splitArray[0];
                    }
                }
                $(".allarea").html(areaTitle);
            } else {
                $(".allarea").html(subtitle);
            }
        }

        for (var i = 0; i < piedata[j].length; i++) {
            if (piedata[j][i].y != 0 ) {
                flag = true;
            }
        }
        if (flag) {
            nodata.hide();
            $(".sta-year-chart").show();
            pieChart.showLoading(".loading");
            for (var i = 0; i < pieChart.series[0].data.length; i++) {
                pieChart.series[0].setData(piedata[j]);
                pieChart.hideLoading();
                if (isYear) {
                    pieChart.setTitle({ text: thisyear + title });
                }

                pieChart.setTitle(null, { text: "共" + totolA[j] + "件" });
            }
        } else {
            nodata.show();
            $(".sta-year-chart").hide();
        }
    });  
}